﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DefensiveShield
{
    /// <summary>
    /// Логика взаимодействия для TextEditor.xaml
    /// </summary>
    
    public partial class TextEditor : Window
    {
        public OsSession Session;
        public string FileName;
        public TextEditor(OsSession session, string fileName, string text)
        {
            InitializeComponent();
            ShowActivated = true;
            FileName = fileName;
            Title = (new FileInfo(FileName)).Name + " - Текстовый редактор";
            TextField.Text = text;
            Session = session;
        }

        private void TextEditorSaveFileButton_Click(object sender, RoutedEventArgs e)
        {
            OS.SaveSecretFile(Session, FileName, TextField.Text);
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
            {
                OS.SaveSecretFile(Session, FileName, TextField.Text);
            }
        }

        private void Window_ContentRendered(object sender, EventArgs e)
        {
            Focus();
        }
    }
}
